package com.shen.thread.demo1;

//多个线程同时操作一个对象,存在并发问题
public class thread4 implements Runnable {
    private int ticketNum = 10;

    @Override
    public void run() {
        while (true) {
            if (ticketNum <= 0) {
                break;
            }
            try {
                Thread.sleep(500);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            System.out.println(Thread.currentThread().getName() + "-->拿到了第" + ticketNum-- + "张票");
        }
    }

    public static void main(String[] args) {
        thread4 thread4 = new thread4();
        new Thread(thread4, "ming").start();
        new Thread(thread4, "hong").start();
        new Thread(thread4, "jack").start();


    }
}
